<template>
  <form-item-setting v-model:config="config">
    <a-form-item
      field="type"
      tooltip=""
      label="开关类型"
    >
      <a-radio-group v-model="config.config.type" type="button">
        <a-radio value="circle">circle</a-radio>
        <a-radio value="round">round</a-radio>
        <a-radio value="line">line</a-radio>
      </a-radio-group>
    </a-form-item>
    <a-form-item
      field="checkedValue"
      tooltip=""
      label="选中时的值"
      :allow-clear="true"
    >
      <a-input v-model="config.config.checkedValue" allow-clear />
    </a-form-item>
    <a-form-item
      field="uncheckedValue"
      tooltip=""
      label="未选中的值"
      :allow-clear="true"
    >
      <a-input v-model="config.config.uncheckedValue" allow-clear />
    </a-form-item>
    <a-form-item
      field="checkedColor"
      tooltip=""
      label="选中颜色"
    >
      <a-color-picker
        v-model="config.config.checkedColor"
        showText
      />
    </a-form-item>
    <a-form-item
      field="uncheckedColor"
      tooltip=""
      label="未选中颜色"
    >
      <a-color-picker
        v-model="config.config.uncheckedColor"
        showText
      />
    </a-form-item>
    <a-form-item
      field="checkedText"
      tooltip="打开状态时的文案（type='line'和size='small'时不生效"
      label="打开文案"
      :allow-clear="true"
    >
      <a-input v-model="config.config.checkedText" allow-clear />
    </a-form-item>
    <a-form-item
      field="uncheckedText"
      tooltip="关闭状态时的文案（type='line'和size='small'时不生效"
      label="关闭文案"
      :allow-clear="true"
    >
      <a-input v-model="config.config.uncheckedText" allow-clear />
    </a-form-item>
    <a-divider style="border-bottom-style: dotted" orientation="center" :size="2" :margin="0">
      事件设置
    </a-divider>
    <br />
    <a-form-item
      field="onChangeFunction"
      tooltip=""
      label="Change"
    >
      <a-button
        type="primary"
        shape="round"
        @click="editOnChange"
      >
        <template #icon>
          <icon-edit />
        </template>
        编辑事件
      </a-button>
      <code-editor
        ref="codeEditorRef"
        v-model:code="config.config.onChangeFunction"
      />
    </a-form-item>
  </form-item-setting>
</template>

<script lang="ts" setup>
import { ref, defineModel } from 'vue';
import FormItemSetting from '@/components/form-design/item-setting/form-item-setting.vue';
import CodeEditor from '@/components/code-editor/index.vue';

const config = defineModel('config');

const codeEditorRef = ref();

const editOnChange = () => {
  codeEditorRef.value.open();
};

</script>

<script lang="ts">
export default {
  name: 'ItemSettingSwitch'
};
</script>

<style scoped>

</style>